﻿using System;
using System.Collections.Generic;
using System.Text;
using SwinGame;

namespace SimpleSurvival.src
{
    //-----------------------------------------------//
    //CLASS - Game.cs
    //-----------------------------------------------//
    //The main state machine for the game//
    public sealed class Game
    {
        Stack<IState> _states = new Stack<IState>();

        //Can add new states to focus on
        public void AddNewTopState(IState s)
        {
            //dont allow duplicate layers if one is found reset the state
            s.LoadContent();
            _states.Push(s);
        }

        //Can remove focus from top state to lower state.
        public void KillTopState() { _states.Pop(); }

        public Game()
        {
            AddNewTopState(new IntroState(this));
        }

        //Draws every state that is visible
        public void Draw(double dt)
        {
            _states.Peek().Draw(dt);
            if (_states.Peek().IsTransparent)
            {
                if (_states.Count > 0)
                {
                    IState x = _states.Pop();
                    Draw(dt);
                    _states.Push(x);
                }
            }
        }

        //Updates every state that is visible
        public void Update(double dt)
        {

            IState cs = _states.Peek();
            if (_states.Count > 1)
            {
                cs = _states.Pop();
                IState ns = _states.Peek();
                if (cs.IsTransparent)
                {
                        Update(dt);
                }
                cs.Update(dt);
                _states.Push(cs);
            }
            else
            {
                cs.Update(dt);
            }
        }
    }

   


   


    





}
